package android.vstore.custom;

import android.graphics.Bitmap;
import android.view.animation.AlphaAnimation;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;

public class FadeInRoundedBitmapDisplayer extends RoundedBitmapDisplayer {

    int durationMillis;
    String noRoundedCornersTag;

    public FadeInRoundedBitmapDisplayer(int durationMillis, int roundPixels,
            String noRoundedCornersTag) {
        super(roundPixels);
        this.durationMillis = durationMillis;
        this.noRoundedCornersTag = noRoundedCornersTag;
    }
    

    @Override
    public void display(Bitmap bitmap, ImageAware imageView,
    		 LoadedFrom loadedFrom) {
    	if(imageView.getWrappedView().getTag() != null && imageView.getWrappedView()
    			.getTag().equals(noRoundedCornersTag)) 
    		imageView.setImageBitmap(bitmap);
    	else
    		super.display(bitmap, imageView, loadedFrom);
                	
//        imageView.setImageBitmap( (imageView.getWrappedView().getTag() != null && imageView.getWrappedView()
//                .getTag().equals(noRoundedCornersTag)) ? bitmap : super
//                .display(bitmap, imageView, loadedFrom));

        animate((ImageView) imageView.getWrappedView(), durationMillis);

//        return bitmap;
    }

    public void animate(ImageView imageView, int durationMillis) {
        AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
        fadeImage.setDuration(durationMillis);
        fadeImage.setInterpolator(new DecelerateInterpolator());
        imageView.startAnimation(fadeImage);
    }

}